<html>
<head><meta charset="utf-8"><title>MaybeUninit&lt;T&gt; is not repr(transparent) · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html">MaybeUninit&lt;T&gt; is not repr(transparent)</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="148069649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148069649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148069649">(Nov 20 2018 at 21:29)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> so the problem is that <code>MaybeUninit&lt;T&gt;</code> does not have the same <code>repr</code> as <code>T</code>, which has performance implications (e.g. if <code>T</code> is <code>repr(simd)</code>) and also means that one cannot use <code>MaybeUninit&lt;T&gt;</code> in C FFI where a <code>T</code> is expected.</p>



<a name="148069723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148069723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148069723">(Nov 20 2018 at 21:30)</a>:</h4>
<p>Given that <code>MaybeUninit&lt;T&gt;</code> is an union with two variants with potentially two different <code>repr</code>s, I don't think that  <code>repr(transparent)</code> makes sense here :/</p>



<a name="148069749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148069749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148069749">(Nov 20 2018 at 21:31)</a>:</h4>
<p>Maybe a way to select from which variant the union gets its <code>repr</code> ?</p>



<a name="148069861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148069861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148069861">(Nov 20 2018 at 21:33)</a>:</h4>
<p>What's been done in <a href="https://github.com/rust-lang/rust/issues/55834" target="_blank" title="https://github.com/rust-lang/rust/issues/55834">#55834</a> is to restrict any ABI fiddling to unions with only one non-(size=0, align=1) field, analogously to how transparent structs can have only one such field</p>



<a name="148069870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148069870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148069870">(Nov 20 2018 at 21:33)</a>:</h4>
<p>But I am puzzled by the mention of FFI. Passing or receiving uninitalized data is UB in C, isn't it?</p>



<a name="148069947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148069947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148069947">(Nov 20 2018 at 21:34)</a>:</h4>
<p>oh no i misrepresented <a href="https://github.com/rust-lang/rust/issues/55834" target="_blank" title="https://github.com/rust-lang/rust/issues/55834">#55834</a> but anyway it doesn't try to handle arbitrary unions with arbitrary fields and that's the key</p>



<a name="148070436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148070436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148070436">(Nov 20 2018 at 21:43)</a>:</h4>
<p>right but its the same restrictions as for repr(transparent) structs as you said</p>



<a name="148070446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148070446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148070446">(Nov 20 2018 at 21:43)</a>:</h4>
<p>so it seems the same attribute would make a lot of sense for unions as well</p>



<a name="148070509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148070509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148070509">(Nov 20 2018 at 21:44)</a>:</h4>
<p>also this is just about deciding which ABI to use to pass these guys around; which further restrictions there are in terms of the values you have in there depends on the language on the other side of the FFI interface</p>



<a name="148070520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148070520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148070520">(Nov 20 2018 at 21:44)</a>:</h4>
<p>and uninitialized data in C is a complicated topic...</p>



<a name="148070575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148070575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148070575">(Nov 20 2018 at 21:45)</a>:</h4>
<p>It's quite complex, yes, but at the end what matters to me is: are there any reasonable Rust programs that benefit from passing MaybeUninit by value across the FFI boundary? Because that is <em>all</em> repr(transparent) is about, you can get any memory layout compatibility you want with repr(C) or (preferably) by Rust deciding to not try to be too clever by half  about union memory layout</p>



<a name="148070718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148070718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148070718">(Nov 20 2018 at 21:48)</a>:</h4>
<p>ack</p>



<a name="148070737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148070737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148070737">(Nov 20 2018 at 21:48)</a>:</h4>
<p>for structs, newtypes are a pretty good argument. but "new-unions" would be a new pattern to me and I dont think I'd like it^^</p>



<a name="148071147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148071147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148071147">(Nov 20 2018 at 21:55)</a>:</h4>
<p><span class="user-mention" data-user-id="124289">@rkruppe</span> I guess the slightly higher-level question is whether there is a good reason for passing what is known to be uninitialized data <em>by value</em> across an FFI boundary. With very few (if any) exceptions, uninitialized data should be inside a <code>MaybeUninit</code></p>



<a name="148071235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148071235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148071235">(Nov 20 2018 at 21:56)</a>:</h4>
<p>well let's hear it from <span class="user-mention" data-user-id="132920">@gnzlbg</span> since they brough up ffi</p>



<a name="148071313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148071313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148071313">(Nov 20 2018 at 21:57)</a>:</h4>
<p>so in stdsimd we use C FFI to call LLVM intrinsics directly...</p>



<a name="148071367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148071367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148071367">(Nov 20 2018 at 21:58)</a>:</h4>
<p>I don't remember if there was a way to obtain <code>undef</code> by doing so, but that's what I had in mind</p>



<a name="148071390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148071390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148071390">(Nov 20 2018 at 21:59)</a>:</h4>
<p>or in other words, just because it is called C FFI does not mean that we are actually doing FFI with C, but for something that exposes the C ABI</p>



<a name="148071413"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148071413" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148071413">(Nov 20 2018 at 21:59)</a>:</h4>
<p>i don't know what the different C ABIs say about uninitialized memory, but probably they just say nothing</p>



<a name="148071516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148071516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148071516">(Nov 20 2018 at 22:00)</a>:</h4>
<p>it seems reasonable to expect these ABIs to require behaving as if the code being called was C, which would mean that callers can assume that the values being passed cannot be uninitialized, don't know</p>



<a name="148071804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148071804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148071804">(Nov 20 2018 at 22:05)</a>:</h4>
<p>so for stdsimd we don't really need any feature, it can just rely on rustc codegen details (as it already does, heavily, in many other places)</p>



<a name="148071894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148071894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148071894">(Nov 20 2018 at 22:06)</a>:</h4>
<p>non-C code using "the C ABI" is interesting, for example one could imagine a Rust library exposing a C ABI, but OTOH I still struggle to imagine needing to pass uninitialized data in those cases</p>



<a name="148078131"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148078131" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148078131">(Nov 21 2018 at 00:03)</a>:</h4>
<p>yeah, me too, i only had in mind using this when interfacing with LLVM</p>



<a name="148095835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148095835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148095835">(Nov 21 2018 at 08:34)</a>:</h4>
<p>where'd you need it when interfacing with LLVM?</p>



<a name="148108513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148108513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148108513">(Nov 21 2018 at 13:08)</a>:</h4>
<p>See: <a href="https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_undefined&amp;expand=5955" target="_blank" title="https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_undefined&amp;expand=5955">https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_undefined&amp;expand=5955</a></p>
<p>All these intrinsics return vectors with "undefined" elements.</p>



<a name="148108574"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148108574" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148108574">(Nov 21 2018 at 13:08)</a>:</h4>
<p>Some of these intrinsics are already in stable, and they should be returning <code>MaybeUninit&lt;__m128&gt;</code> instead of just <code>__m128</code>.</p>



<a name="148108595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148108595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148108595">(Nov 21 2018 at 13:09)</a>:</h4>
<p>Once we can use <code>MaybeUninit</code> in stable APIs, we should try to fix those in a backwards incompatible way (doing a crater run, etc.)</p>



<a name="148108613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148108613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148108613">(Nov 21 2018 at 13:09)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> but to construct an <code>MaybeUninit&lt;__m128&gt;</code> you don't need an intrinsic</p>



<a name="148108617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148108617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148108617">(Nov 21 2018 at 13:09)</a>:</h4>
<p>just use <code>MaybeUninit::uninitialized()</code></p>



<a name="148108670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148108670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148108670">(Nov 21 2018 at 13:10)</a>:</h4>
<p>indeed, I don't know why I have in mind that we were calling into LLVM intrinsics for any of those</p>



<a name="148108695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148108695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148108695">(Nov 21 2018 at 13:11)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> can we use <code>MaybeUninit</code> in stable APIs already ?</p>



<a name="148108764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148108764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148108764">(Nov 21 2018 at 13:12)</a>:</h4>
<p>that is, is <code>MaybeUninit</code> already stable ?</p>



<a name="148108787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148108787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148108787">(Nov 21 2018 at 13:12)</a>:</h4>
<p>Also, the intrinsics "construct a vector with uninitialized elements".</p>



<a name="148108796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148108796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148108796">(Nov 21 2018 at 13:13)</a>:</h4>
<p>Checking the source code for some, they are built by using <code>__m128(uninitialized(), uninitialized(), ...)</code></p>



<a name="148108807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148108807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148108807">(Nov 21 2018 at 13:13)</a>:</h4>
<p>and not just <code>uninitialized::&lt;__m128&gt;()</code> for some reason</p>



<a name="148108877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148108877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148108877">(Nov 21 2018 at 13:15)</a>:</h4>
<blockquote>
<p>that is, is <code>MaybeUninit</code> already stable ?</p>
</blockquote>
<p>no</p>



<a name="148108885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148108885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148108885">(Nov 21 2018 at 13:15)</a>:</h4>
<p>we should first get <a href="https://github.com/rust-lang/rust/pull/54668" target="_blank" title="https://github.com/rust-lang/rust/pull/54668">https://github.com/rust-lang/rust/pull/54668</a> landed</p>



<a name="148108892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit%3CT%3E%20is%20not%20repr%28transparent%29/near/148108892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/MaybeUninit.3CT.3E.20is.20not.20repr(transparent).html#148108892">(Nov 21 2018 at 13:15)</a>:</h4>
<p>and there are some API discussions in the tracking issue</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>